<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>轮播图的实现 | Danyhug's Blog</title><meta name="author" content="Danyhug"><meta name="copyright" content="Danyhug"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><meta name="description" content="前言：学习了js和css后，想学着写一个轮播图，基本功能都能实现，但是如果鼠标切换的太快，获取元素的宽度会少一些，一个少个个少，最终就导致这个轮播图只能看不能点，基本上一碰就bug百出，所以决定自己试着写一个  先上代码12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849">
<meta property="og:type" content="article">
<meta property="og:title" content="轮播图的实现">
<meta property="og:url" content="http://danyhug.gitee.io/blog/2021/04/29/%E8%BD%AE%E6%92%AD%E5%9B%BE%E7%9A%84%E5%AE%9E%E7%8E%B0/index.html">
<meta property="og:site_name" content="Danyhug&#39;s Blog">
<meta property="og:description" content="前言：学习了js和css后，想学着写一个轮播图，基本功能都能实现，但是如果鼠标切换的太快，获取元素的宽度会少一些，一个少个个少，最终就导致这个轮播图只能看不能点，基本上一碰就bug百出，所以决定自己试着写一个  先上代码12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://danyhug.gitee.io/blog/img/bgimg/1.jpg">
<meta property="article:published_time" content="2021-04-29T08:10:46.000Z">
<meta property="article:modified_time" content="2021-05-03T12:28:04.432Z">
<meta property="article:author" content="Danyhug">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://danyhug.gitee.io/blog/img/bgimg/1.jpg"><link rel="shortcut icon" href="/blog/img/favicon.png"><link rel="canonical" href="http://danyhug.gitee.io/blog/2021/04/29/%E8%BD%AE%E6%92%AD%E5%9B%BE%E7%9A%84%E5%AE%9E%E7%8E%B0/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/blog/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><script>var GLOBAL_CONFIG = { 
  root: '/blog/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: false
};

var saveToLocal = {
  set: function setWithExpiry(key, value, ttl) {
    const now = new Date()
    const expiryDay = ttl * 86400000
    const item = {
      value: value,
      expiry: now.getTime() + expiryDay,
    }
    localStorage.setItem(key, JSON.stringify(item))
  },

  get: function getWithExpiry(key) {
    const itemStr = localStorage.getItem(key)

    if (!itemStr) {
      return undefined
    }
    const item = JSON.parse(itemStr)
    const now = new Date()

    if (now.getTime() > item.expiry) {
      localStorage.removeItem(key)
      return undefined
    }
    return item.value
  }
}

// https://stackoverflow.com/questions/16839698/jquery-getscript-alternative-in-native-javascript
const getScript = url => new Promise((resolve, reject) => {
  const script = document.createElement('script')
  script.src = url
  script.async = true
  script.onerror = reject
  script.onload = script.onreadystatechange = function() {
    const loadState = this.readyState
    if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
    script.onload = script.onreadystatechange = null
    resolve()
  }
  document.head.appendChild(script)
})</script><script id="config_change">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2021-05-03 20:28:04'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(function () {  window.activateDarkMode = function () {
    document.documentElement.setAttribute('data-theme', 'dark')
    if (document.querySelector('meta[name="theme-color"]') !== null) {
      document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
    }
  }
  window.activateLightMode = function () {
    document.documentElement.setAttribute('data-theme', 'light')
   if (document.querySelector('meta[name="theme-color"]') !== null) {
      document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
    }
  }
  const autoChangeMode = 'false'
  const t = saveToLocal.get('theme')
  if (autoChangeMode === '1') {
    const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
    const isLightMode = window.matchMedia('(prefers-color-scheme: light)').matches
    const isNotSpecified = window.matchMedia('(prefers-color-scheme: no-preference)').matches
    const hasNoSupport = !isDarkMode && !isLightMode && !isNotSpecified
    if (t === undefined) {
      if (isLightMode) activateLightMode()
      else if (isDarkMode) activateDarkMode()
      else if (isNotSpecified || hasNoSupport) {
        const now = new Date()
        const hour = now.getHours()
        const isNight = hour <= 6 || hour >= 18
        isNight ? activateDarkMode() : activateLightMode()
      }
      window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
        if (saveToLocal.get('theme') === undefined) {
          e.matches ? activateDarkMode() : activateLightMode()
        }
      })
    } else if (t === 'light') activateLightMode()
    else activateDarkMode()
  } else if (autoChangeMode === '2') {
    const now = new Date()
    const hour = now.getHours()
    const isNight = hour <= 6 || hour >= 18
    if (t === undefined) isNight ? activateDarkMode() : activateLightMode()
    else if (t === 'light') activateLightMode()
    else activateDarkMode()
  } else {
    if (t === 'dark') activateDarkMode()
    else if (t === 'light') activateLightMode()
  }const asideStatus = saveToLocal.get('aside-status')
if (asideStatus !== undefined) {
   if (asideStatus === 'hide') {
     document.documentElement.classList.add('hide-aside')
   } else {
     document.documentElement.classList.remove('hide-aside')
   }
}const fontSizeVal = saveToLocal.get('global-font-size')
if (fontSizeVal !== undefined) {
  document.documentElement.style.setProperty('--global-font-size', fontSizeVal + 'px')
}})()</script><meta name="generator" content="Hexo 5.3.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" src="http://q1.qlogo.cn/g?b=qq&amp;nk=153669225&amp;s=100" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">33</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">18</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">5</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/blog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url(/blog/img/bgimg/1.jpg)"><nav id="nav"><span id="blog_name"><a id="site-name" href="/blog/">Danyhug's Blog</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/blog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">轮播图的实现</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-04-29T08:10:46.000Z" title="发表于 2021-04-29 16:10:46">2021-04-29</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-05-03T12:28:04.432Z" title="更新于 2021-05-03 20:28:04">2021-05-03</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><blockquote>
<p>前言：学习了js和css后，想学着写一个轮播图，基本功能都能实现，但是如果鼠标切换的太快，获取元素的宽度会少一些，一个少个个少，最终就导致这个轮播图只能看不能点，基本上一碰就bug百出，所以决定自己试着写一个</p>
</blockquote>
<h3 id="先上代码"><a href="#先上代码" class="headerlink" title="先上代码"></a>先上代码</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;utf-8&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">title</span>&gt;</span><span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">style</span> <span class="attr">type</span>=<span class="string">&quot;text/css&quot;</span>&gt;</span></span><br><span class="line"><span class="css">      <span class="keyword">@media</span> screen <span class="keyword">and</span> (<span class="attribute">max-width:</span> <span class="number">1200px</span>) &#123;</span></span><br><span class="line"><span class="css">        <span class="selector-tag">body</span> <span class="selector-class">.nav</span> &#123;</span></span><br><span class="line">          width: 550px;</span><br><span class="line">          height: 550px;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line"><span class="css">        <span class="selector-class">.nav</span> <span class="selector-class">.nav-list</span>&gt;<span class="selector-tag">li</span> &#123;</span></span><br><span class="line">          width: 550px;</span><br><span class="line">          height: 550px;</span><br><span class="line">          font-size: 150px;</span><br><span class="line">          line-height: 550px;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line"><span class="css">      <span class="keyword">@media</span> screen <span class="keyword">and</span> (<span class="attribute">max-width:</span> <span class="number">750px</span>) &#123;</span></span><br><span class="line"><span class="css">        <span class="selector-tag">body</span> <span class="selector-class">.nav</span> &#123;</span></span><br><span class="line">          width: 450px;</span><br><span class="line">          height: 450px;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line"><span class="css">        <span class="selector-class">.nav</span> <span class="selector-class">.nav-list</span>&gt;<span class="selector-tag">li</span> &#123;</span></span><br><span class="line">          width: 450px;</span><br><span class="line">          height: 450px;</span><br><span class="line">          font-size: 130px;</span><br><span class="line">          line-height: 450px;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line"><span class="css">      <span class="keyword">@media</span> screen <span class="keyword">and</span> (<span class="attribute">max-width:</span> <span class="number">500px</span>) &#123;</span></span><br><span class="line"><span class="css">        <span class="selector-tag">body</span> <span class="selector-class">.nav</span> &#123;</span></span><br><span class="line">          width: 300px;</span><br><span class="line">          height: 300px;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line"><span class="css">        <span class="selector-class">.nav</span> <span class="selector-class">.nav-list</span>&gt;<span class="selector-tag">li</span> &#123;</span></span><br><span class="line">          width: 300px;</span><br><span class="line">          height: 300px;</span><br><span class="line">          font-size: 100px;</span><br><span class="line">          line-height: 300px;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line">      * &#123;</span><br><span class="line">        margin: 0;</span><br><span class="line">        padding: 0;</span><br><span class="line">        box-sizing: border-box;</span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line">      ul &#123;</span><br><span class="line">        list-style: none;</span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line"><span class="css">      <span class="selector-class">.nav</span> &#123;</span></span><br><span class="line">        width: 600px;</span><br><span class="line">        height: 600px;</span><br><span class="line">        margin: 0 auto;</span><br><span class="line">        overflow: hidden;</span><br><span class="line">        position: relative;</span><br><span class="line"><span class="css">        <span class="selector-tag">background-color</span>: <span class="selector-id">#000000</span>;</span></span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line"><span class="css">      <span class="selector-class">.btn</span> &#123;</span></span><br><span class="line">        width: 100%;</span><br><span class="line">        position: absolute;</span><br><span class="line">        top: 50%;</span><br><span class="line">        transform: translateY(-50%);</span><br><span class="line"><span class="css">        <span class="selector-tag">color</span>: <span class="selector-id">#FFFFFF</span>;</span></span><br><span class="line">        display: flex;</span><br><span class="line">        justify-content: space-between;</span><br><span class="line">        font-size: 120px;</span><br><span class="line">        z-index: 100;</span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line"><span class="css">      <span class="selector-class">.btn</span>&gt;<span class="selector-tag">div</span> &#123;</span></span><br><span class="line">        cursor: pointer;</span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line"><span class="css">      <span class="selector-class">.nav-list</span> &#123;</span></span><br><span class="line">        word-spacing: -1em;</span><br><span class="line">        transition: transform 1s;</span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line"><span class="css">      <span class="selector-class">.nav-list</span>&gt;<span class="selector-tag">li</span> &#123;</span></span><br><span class="line">        width: 600px;</span><br><span class="line">        height: 600px;</span><br><span class="line">        display: inline-block;</span><br><span class="line">        text-align: center;</span><br><span class="line">        line-height: 600px;</span><br><span class="line">        font-size: 200px;</span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line"><span class="css">      <span class="selector-tag">li</span><span class="selector-pseudo">:nth-child(1)</span> &#123;</span></span><br><span class="line">        background-color: red;</span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line"><span class="css">      <span class="selector-tag">li</span><span class="selector-pseudo">:nth-child(2)</span> &#123;</span></span><br><span class="line">        background-color: green;</span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line"><span class="css">      <span class="selector-tag">li</span><span class="selector-pseudo">:nth-child(3)</span> &#123;</span></span><br><span class="line">        background-color: blue;</span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line"><span class="css">      <span class="selector-tag">li</span><span class="selector-pseudo">:nth-child(4)</span> &#123;</span></span><br><span class="line">        background-color: yellow;</span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line"><span class="css">      <span class="selector-tag">li</span><span class="selector-pseudo">:nth-child(5)</span> &#123;</span></span><br><span class="line">        background-color: hotpink;</span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line"><span class="css">      <span class="selector-tag">li</span><span class="selector-pseudo">:nth-child(6)</span> &#123;</span></span><br><span class="line">        background-color: orange;</span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line"><span class="css">      <span class="selector-tag">li</span><span class="selector-pseudo">:nth-child(7)</span> &#123;</span></span><br><span class="line">        background-color: purple;</span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line"><span class="css">      <span class="selector-tag">li</span><span class="selector-pseudo">:nth-child(8)</span> &#123;</span></span><br><span class="line">        background-color: aqua;</span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line"><span class="css">      <span class="selector-class">.num-items</span> &#123;</span></span><br><span class="line">        position: absolute;</span><br><span class="line">        bottom: 30px;</span><br><span class="line">        width: 100%;</span><br><span class="line">        font-size: 0;</span><br><span class="line">        text-align: center;</span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line"><span class="css">      <span class="selector-class">.num-items</span>&gt;<span class="selector-class">.num-item</span> &#123;</span></span><br><span class="line">        display: inline-block;</span><br><span class="line">        width: 14px;</span><br><span class="line">        height: 14px;</span><br><span class="line">        margin: 0 6px;</span><br><span class="line">        border-radius: 50%;</span><br><span class="line"><span class="css">        <span class="selector-tag">background-color</span>: <span class="selector-id">#FFFFFF</span>;</span></span><br><span class="line"><span class="css">        <span class="selector-tag">border</span>: 2<span class="selector-tag">px</span> <span class="selector-tag">solid</span> <span class="selector-id">#FFFFFF</span>;</span></span><br><span class="line">        cursor: pointer;</span><br><span class="line">        transition: background-color .4s;</span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line"><span class="css">      <span class="selector-class">.num-items</span> <span class="selector-class">.current</span> &#123;</span></span><br><span class="line"><span class="css">        <span class="selector-tag">background-color</span>: <span class="selector-id">#3366CC</span>;</span></span><br><span class="line">      &#125;</span><br><span class="line">    <span class="tag">&lt;/<span class="name">style</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">nav</span> <span class="attr">class</span>=<span class="string">&quot;nav&quot;</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;btn&quot;</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;leftBtn&quot;</span>&gt;</span><span class="symbol">&amp;lt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;rightBtn&quot;</span>&gt;</span><span class="symbol">&amp;gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">ul</span> <span class="attr">class</span>=<span class="string">&quot;nav-list&quot;</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">li</span> <span class="attr">class</span>=<span class="string">&quot;list-it&quot;</span>&gt;</span>1<span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">li</span> <span class="attr">class</span>=<span class="string">&quot;list-it&quot;</span>&gt;</span>2<span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">li</span> <span class="attr">class</span>=<span class="string">&quot;list-it&quot;</span>&gt;</span>3<span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">li</span> <span class="attr">class</span>=<span class="string">&quot;list-it&quot;</span>&gt;</span>4<span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">li</span> <span class="attr">class</span>=<span class="string">&quot;list-it&quot;</span>&gt;</span>5<span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">li</span> <span class="attr">class</span>=<span class="string">&quot;list-it&quot;</span>&gt;</span>6<span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">li</span> <span class="attr">class</span>=<span class="string">&quot;list-it&quot;</span>&gt;</span>7<span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">li</span> <span class="attr">class</span>=<span class="string">&quot;list-it&quot;</span>&gt;</span>8<span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;/<span class="name">ul</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">ul</span> <span class="attr">class</span>=<span class="string">&quot;num-items&quot;</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">li</span> <span class="attr">class</span>=<span class="string">&quot;num-item current&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">li</span> <span class="attr">class</span>=<span class="string">&quot;num-item&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">li</span> <span class="attr">class</span>=<span class="string">&quot;num-item&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">li</span> <span class="attr">class</span>=<span class="string">&quot;num-item&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">li</span> <span class="attr">class</span>=<span class="string">&quot;num-item&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">li</span> <span class="attr">class</span>=<span class="string">&quot;num-item&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">li</span> <span class="attr">class</span>=<span class="string">&quot;num-item&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">li</span> <span class="attr">class</span>=<span class="string">&quot;num-item&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;/<span class="name">ul</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">nav</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;jQuery/js/jquery-3.6.0.min.js&quot;</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span> <span class="attr">charset</span>=<span class="string">&quot;utf-8&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span>&gt;</span></span><br><span class="line"><span class="javascript">  $(<span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">    <span class="comment">// 获取按钮</span></span></span><br><span class="line"><span class="javascript">    <span class="keyword">var</span> leftBtn = $(<span class="string">&#x27;.leftBtn&#x27;</span>),</span></span><br><span class="line"><span class="javascript">      rightBtn = $(<span class="string">&#x27;.rightBtn&#x27;</span>);</span></span><br><span class="line"><span class="javascript">    <span class="comment">// 获取列表</span></span></span><br><span class="line"><span class="javascript">    <span class="keyword">var</span> ul = $(<span class="string">&#x27;.nav-list&#x27;</span>);</span></span><br><span class="line"><span class="javascript">    <span class="comment">// 下方按钮</span></span></span><br><span class="line"><span class="javascript">    <span class="keyword">var</span> numItems = $(<span class="string">&#x27;.num-item&#x27;</span>);</span></span><br><span class="line"><span class="javascript">    <span class="comment">// 列表的最大索引值</span></span></span><br><span class="line">    maxArr = ul.children().length - 1;</span><br><span class="line"><span class="javascript">    <span class="comment">// 列表的最小索引值</span></span></span><br><span class="line">    minArr = 0;</span><br><span class="line"><span class="javascript">    <span class="comment">// 定时器</span></span></span><br><span class="line"><span class="javascript">    <span class="keyword">var</span> timer = <span class="literal">null</span>;</span></span><br><span class="line"></span><br><span class="line"><span class="javascript">    <span class="comment">// 子列表宽度</span></span></span><br><span class="line"><span class="javascript">    <span class="keyword">var</span> eleWidth = ul.children().width();</span></span><br><span class="line"><span class="javascript">    <span class="comment">// 根据子元素改变列表的宽度</span></span></span><br><span class="line"><span class="javascript">    ul.css(<span class="string">&#x27;width&#x27;</span>, eleWidth * (maxArr + <span class="number">1</span>))</span></span><br><span class="line"></span><br><span class="line"><span class="javascript">    <span class="comment">// 当前选中</span></span></span><br><span class="line"><span class="javascript">    <span class="keyword">var</span> currIndex = <span class="number">0</span>;</span></span><br><span class="line"><span class="javascript">    <span class="comment">// 对应的位置数组</span></span></span><br><span class="line"><span class="javascript">    <span class="keyword">var</span> widthArr = <span class="keyword">new</span> <span class="built_in">Array</span>();</span></span><br><span class="line"><span class="javascript">    <span class="keyword">for</span> (<span class="keyword">let</span> i = <span class="number">0</span>; i &lt;= maxArr; i++) &#123;</span></span><br><span class="line">      widthArr[i] = i * -eleWidth;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"><span class="javascript">    <span class="comment">// 用于切换按钮的函数</span></span></span><br><span class="line"><span class="javascript">    <span class="function"><span class="keyword">function</span> <span class="title">toggleNumItem</span>(<span class="params"></span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">      numItems.removeClass(<span class="string">&#x27;current&#x27;</span>);</span></span><br><span class="line"><span class="javascript">      numItems.eq(currIndex).addClass(<span class="string">&#x27;current&#x27;</span>);</span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"><span class="javascript">    <span class="comment">// 左方向键点击</span></span></span><br><span class="line"><span class="javascript">    leftBtn.on(<span class="string">&#x27;click&#x27;</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span></span><br><span class="line">      currIndex--;</span><br><span class="line"><span class="javascript">      <span class="keyword">if</span> (currIndex &lt; minArr) &#123;</span></span><br><span class="line">        currIndex = maxArr;</span><br><span class="line">      &#125;</span><br><span class="line"><span class="javascript">      <span class="comment">// 当前轮播图2D的x轴值</span></span></span><br><span class="line"><span class="javascript">      <span class="keyword">var</span> translatex = widthArr[currIndex];</span></span><br><span class="line"><span class="javascript">      ul.css(<span class="string">&#x27;transform&#x27;</span>, <span class="string">&#x27;translateX(&#x27;</span> + translatex + <span class="string">&#x27;px)&#x27;</span>);</span></span><br><span class="line">      toggleNumItem();</span><br><span class="line">    &#125;)</span><br><span class="line"><span class="javascript">    <span class="comment">// 右方向键点击</span></span></span><br><span class="line"><span class="javascript">    rightBtn.on(<span class="string">&#x27;click&#x27;</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span></span><br><span class="line">      currIndex++;</span><br><span class="line"><span class="javascript">      <span class="keyword">if</span> (currIndex &gt; maxArr) &#123;</span></span><br><span class="line">        currIndex = minArr;</span><br><span class="line">      &#125;</span><br><span class="line"><span class="javascript">      <span class="comment">// 当前轮播图2D的x轴值</span></span></span><br><span class="line"><span class="javascript">      <span class="keyword">var</span> translatex = widthArr[currIndex];</span></span><br><span class="line"><span class="javascript">      ul.css(<span class="string">&#x27;transform&#x27;</span>, <span class="string">&#x27;translateX(&#x27;</span> + translatex + <span class="string">&#x27;px)&#x27;</span>);</span></span><br><span class="line">      toggleNumItem();</span><br><span class="line">    &#125;)</span><br><span class="line"></span><br><span class="line"><span class="javascript">    <span class="comment">// 自动轮播</span></span></span><br><span class="line"><span class="javascript">    <span class="function"><span class="keyword">function</span> <span class="title">autoSlide</span>(<span class="params"></span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">      <span class="comment">// 更改当前li的索引值</span></span></span><br><span class="line">      currIndex++;</span><br><span class="line"><span class="javascript">      <span class="keyword">if</span> (currIndex &gt; maxArr) &#123;</span></span><br><span class="line">        currIndex = minArr;</span><br><span class="line"><span class="javascript">      &#125; <span class="keyword">else</span> <span class="keyword">if</span> (currIndex &lt; minArr) &#123;</span></span><br><span class="line">        currIndex = maxArr;</span><br><span class="line">      &#125;</span><br><span class="line"><span class="javascript">      <span class="comment">// 当前轮播图2D的x轴值</span></span></span><br><span class="line"><span class="javascript">      <span class="keyword">var</span> translatex = widthArr[currIndex];</span></span><br><span class="line"><span class="javascript">      ul.css(<span class="string">&#x27;transform&#x27;</span>, <span class="string">&#x27;translateX(&#x27;</span> + translatex + <span class="string">&#x27;px)&#x27;</span>);</span></span><br><span class="line">      toggleNumItem();</span><br><span class="line">    &#125;</span><br><span class="line"><span class="javascript">    timer = <span class="built_in">setInterval</span>(autoSlide, <span class="number">1000</span>);</span></span><br><span class="line"><span class="javascript">    <span class="comment">// 划入轮播图时停止自动轮播</span></span></span><br><span class="line"><span class="javascript">    $(<span class="string">&#x27;.nav&#x27;</span>).hover(<span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">      <span class="comment">// 清空计时器</span></span></span><br><span class="line"><span class="javascript">      <span class="built_in">clearInterval</span>(timer);</span></span><br><span class="line"><span class="javascript">    &#125;, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">      <span class="comment">// 加入计时器</span></span></span><br><span class="line"><span class="javascript">      timer = <span class="built_in">setInterval</span>(autoSlide, <span class="number">1000</span>);</span></span><br><span class="line">    &#125;)</span><br><span class="line"></span><br><span class="line"><span class="javascript">    <span class="comment">// 滑动到下方按钮时,更改对应li的类名</span></span></span><br><span class="line"><span class="javascript">    numItems.hover(<span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">      <span class="keyword">var</span> index = $(<span class="built_in">this</span>).index();</span></span><br><span class="line"><span class="javascript">      $(<span class="built_in">this</span>).addClass(<span class="string">&#x27;current&#x27;</span>);</span></span><br><span class="line"><span class="javascript">      <span class="comment">// 排他思想</span></span></span><br><span class="line"><span class="javascript">      $(<span class="built_in">this</span>).siblings().removeClass(<span class="string">&#x27;current&#x27;</span>);</span></span><br><span class="line">      currIndex = index;</span><br><span class="line"><span class="javascript">      <span class="keyword">var</span> translatex = widthArr[currIndex];</span></span><br><span class="line"><span class="javascript">      ul.css(<span class="string">&#x27;transform&#x27;</span>, <span class="string">&#x27;translateX(&#x27;</span> + translatex + <span class="string">&#x27;px)&#x27;</span>);</span></span><br><span class="line">    &#125;)</span><br><span class="line"></span><br><span class="line"><span class="javascript">    <span class="comment">// 实时检测窗口变化</span></span></span><br><span class="line"><span class="javascript">    <span class="built_in">window</span>.onresize = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">      <span class="comment">// 子列表宽度</span></span></span><br><span class="line">      eleWidth = ul.children().width();</span><br><span class="line"><span class="javascript">      <span class="comment">// 根据子元素改变列表的宽度</span></span></span><br><span class="line"><span class="javascript">      ul.css(<span class="string">&#x27;width&#x27;</span>, eleWidth * (maxArr + <span class="number">1</span>))</span></span><br><span class="line"></span><br><span class="line"><span class="javascript">      <span class="comment">// 对应的位置数组</span></span></span><br><span class="line"><span class="javascript">      widthArr = <span class="keyword">new</span> <span class="built_in">Array</span>();</span></span><br><span class="line"><span class="javascript">      <span class="keyword">for</span> (<span class="keyword">let</span> i = <span class="number">0</span>; i &lt;= maxArr; i++) &#123;</span></span><br><span class="line">        widthArr[i] = i * -eleWidth;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;)</span><br><span class="line"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h3 id="最终效果"><a href="#最终效果" class="headerlink" title="最终效果"></a>最终效果</h3><p><img src="C:\Users\Danyhug\blog\themes\butterfly\source\img\postimg\image-20210429161446977.png" alt="image-20210429161446977"></p>
<h3 id="实现功能"><a href="#实现功能" class="headerlink" title="实现功能"></a>实现功能</h3><ul>
<li>无论再增加多少个轮播图，都可以自行适应，正常使用</li>
<li>左右按钮就算是按的再快也不会出现显示一半的情况</li>
<li>滑动到下方小圆点时会自动切换轮播图，并添加对应样式</li>
<li>可以自动轮播</li>
</ul>
<h3 id="如何使用"><a href="#如何使用" class="headerlink" title="如何使用"></a>如何使用</h3><ul>
<li>只需要给.nav-list的子元素li添加对应的宽高，然后添加对应数量的小圆点，即可使用</li>
<li>因为这是为了比赛准备，而且也为了省事，所以直接用jQuery完成，原则上根据轮播图数量添加小圆点不难实现，但感觉对比赛没什么用，就不增添新的bug了</li>
</ul>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">Danyhug</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://danyhug.gitee.io/blog/2021/04/29/%E8%BD%AE%E6%92%AD%E5%9B%BE%E7%9A%84%E5%AE%9E%E7%8E%B0/">http://danyhug.gitee.io/blog/2021/04/29/轮播图的实现/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://danyhug.gitee.io/blog" target="_blank">Danyhug's Blog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"><div class="social-share" data-image="/blog/img/bgimg/1.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/blog/2021/05/09/jQuery%E7%9A%84%E4%B8%80%E4%BA%9B%E6%93%8D%E4%BD%9C/"><img class="prev-cover" src="/blog/img/bgimg/6.jpg" onerror="onerror=null;src='/blog/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">jQuery的一些操作</div></div></a></div><div class="next-post pull-right"><a href="/blog/2021/04/23/MYSQL/"><img class="next-cover" src="/blog/img/bgimg/9.jpg" onerror="onerror=null;src='/blog/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">MYSQL</div></div></a></div></nav></div><div class="aside_content" id="aside_content"><div class="card-widget card-info"><div class="card-content"><div class="card-info-avatar is-center"><img class="avatar-img" src="http://q1.qlogo.cn/g?b=qq&amp;nk=153669225&amp;s=100" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">Danyhug</div><div class="author-info__description"></div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">33</div></a></div><div class="card-info-data-item is-center"><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">18</div></a></div><div class="card-info-data-item is-center"><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">5</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://gitee.com/danyhug"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://gitee.com/danyhug" target="_blank" title="Gitee"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:danyhug@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div></div><div class="card-widget card-announcement"><div class="card-content"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="card-content"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%88%E4%B8%8A%E4%BB%A3%E7%A0%81"><span class="toc-number">1.</span> <span class="toc-text">先上代码</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9C%80%E7%BB%88%E6%95%88%E6%9E%9C"><span class="toc-number">2.</span> <span class="toc-text">最终效果</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AE%9E%E7%8E%B0%E5%8A%9F%E8%83%BD"><span class="toc-number">3.</span> <span class="toc-text">实现功能</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8"><span class="toc-number">4.</span> <span class="toc-text">如何使用</span></a></li></ol></div></div></div><div class="card-widget card-recent-post"><div class="card-content"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/blog/2021/05/09/jQuery%E7%9A%84%E4%B8%80%E4%BA%9B%E6%93%8D%E4%BD%9C/" title="jQuery的一些操作"><img src="/blog/img/bgimg/6.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="jQuery的一些操作"/></a><div class="content"><a class="title" href="/blog/2021/05/09/jQuery%E7%9A%84%E4%B8%80%E4%BA%9B%E6%93%8D%E4%BD%9C/" title="jQuery的一些操作">jQuery的一些操作</a><time datetime="2021-05-09T02:43:29.000Z" title="发表于 2021-05-09 10:43:29">2021-05-09</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2021/04/29/%E8%BD%AE%E6%92%AD%E5%9B%BE%E7%9A%84%E5%AE%9E%E7%8E%B0/" title="轮播图的实现"><img src="/blog/img/bgimg/1.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="轮播图的实现"/></a><div class="content"><a class="title" href="/blog/2021/04/29/%E8%BD%AE%E6%92%AD%E5%9B%BE%E7%9A%84%E5%AE%9E%E7%8E%B0/" title="轮播图的实现">轮播图的实现</a><time datetime="2021-04-29T08:10:46.000Z" title="发表于 2021-04-29 16:10:46">2021-04-29</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2021/04/23/MYSQL/" title="MYSQL"><img src="/blog/img/bgimg/9.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="MYSQL"/></a><div class="content"><a class="title" href="/blog/2021/04/23/MYSQL/" title="MYSQL">MYSQL</a><time datetime="2021-04-23T12:22:02.000Z" title="发表于 2021-04-23 20:22:02">2021-04-23</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2021/03/17/CSS%E6%8A%80%E5%B7%A7/" title="CSS技巧"><img src="/blog/img/bgimg/4.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="CSS技巧"/></a><div class="content"><a class="title" href="/blog/2021/03/17/CSS%E6%8A%80%E5%B7%A7/" title="CSS技巧">CSS技巧</a><time datetime="2021-03-17T04:25:15.000Z" title="发表于 2021-03-17 12:25:15">2021-03-17</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2021/02/24/%E6%B6%85%E6%99%AEMISC01-%E5%9B%BE%E7%89%87%E9%9A%90%E5%86%99/" title="涅普MISC01-图片隐写"><img src="/blog/img/bgimg/1.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="涅普MISC01-图片隐写"/></a><div class="content"><a class="title" href="/blog/2021/02/24/%E6%B6%85%E6%99%AEMISC01-%E5%9B%BE%E7%89%87%E9%9A%90%E5%86%99/" title="涅普MISC01-图片隐写">涅普MISC01-图片隐写</a><time datetime="2021-02-24T03:29:38.000Z" title="发表于 2021-02-24 11:29:38">2021-02-24</time></div></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2021 By Danyhug</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="font-plus" type="button" title="放大字体"><i class="fas fa-plus"></i></button><button id="font-minus" type="button" title="缩小字体"><i class="fas fa-minus"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/blog/js/utils.js"></script><script src="/blog/js/main.js"></script><div class="js-pjax"><script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><script defer id="ribbon" src="http://danyhug.gitee.io/blog/js/canvas-ribbon.min.js" size="150" alpha="0.6" zindex="-1" mobile="true" data-click="true"></script></div></body></html>